package cqrtplm.controller;

import com.github.pagehelper.PageInfo;
import com.ty.basic.response.ResponseResult;
import cqrtplm.constant.RouteConstant;
import cqrtplm.dto.RTDescribeInformationDTO;
import cqrtplm.dto.RTDescribeInformationlDTO;
import cqrtplm.entity.RTDescribeInformationDO;
import cqrtplm.service.RTEngraveService;
import cqrtplm.vo.RTEngraveDemandStatusVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.List;

@RestController
@Api(tags = "打刻")
@RequestMapping(RouteConstant.ENGRAVEMENT + "v1")
public class RTEngraveController {

    @Resource
    private RTEngraveService rtEngraveService;


    @GetMapping("/queryEngraveDetail")
    @ApiOperation(value = "维护打刻数据基础信息")
    public ResponseResult<RTDescribeInformationDTO> queryEngraveDetail() {
        return rtEngraveService.queryEngraveDetail();
    }

    @PostMapping("/addEngraveDetails")
    @ApiOperation(value = "新增打刻数据", produces = "application/json; charset=utf-8")
    public ResponseResult<RTDescribeInformationDO> addEngraveDetails(@RequestBody RTEngraveDemandStatusVO rtDescribeInformationDO) {
        return rtEngraveService.addEngraveDetails(rtDescribeInformationDO);
    }

    @PutMapping("/stopEngraveDetail")
    @ApiOperation(value = "停用打刻数据", produces = "application/json; charset=utf-8")
    public ResponseResult stopEngraveDetail(@RequestBody RTDescribeInformationDO rtDescribeInformationDO) {
        return rtEngraveService.stopEngraveDetail(rtDescribeInformationDO);
    }

    @GetMapping("/search")
    @ApiOperation(value = "查询打刻信息")
    public ResponseResult<PageInfo<RTDescribeInformationDO>> search(
            @RequestParam(required = false) String describeInformationCode,
            @RequestParam(required = false) String engraveName,
            @RequestParam(required = false) String row1Rule1,
            @RequestParam(required = false) String row2Rule1,
            @RequestParam(required = false) String row3Rule1,
            @RequestParam(required = false) String row4Rule1,
            @RequestParam(required = false) String row5Rule1,

            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "20") int pageSize) {
        PageInfo<RTDescribeInformationDO> pageInfo = rtEngraveService.searchByDescribeInformationCode(describeInformationCode,engraveName, page, pageSize,row1Rule1,row2Rule1,row3Rule1,row4Rule1,row5Rule1);
        return ResponseResult.success(pageInfo);
    }

    @GetMapping("/searchByEngrave")
    public ResponseResult searchByEngrave(
            @RequestParam String engraveContent,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "20") int pageSize) {
        PageInfo<RTEngraveDemandStatusVO> pageInfo=  rtEngraveService.queryEngraveDemandStatus(engraveContent, page, pageSize);
        return ResponseResult.success(pageInfo);
    }


    @PostMapping ("/deleteEngraveDetail")
    @ApiOperation(value = "删除打刻数据", produces = "application/json; charset=utf-8")
    public ResponseResult deleteEngraveDetail(@RequestBody List<BigInteger> OIds) {
        rtEngraveService.deleteEngraveDetail(OIds);
        return ResponseResult.success();
    }

    @PutMapping("/updateStatusCode")
    @ApiOperation(value = "更改状态需求表", produces = "application/json; charset=utf-8")
    public ResponseResult updateStatusCode(@RequestBody RTDescribeInformationlDTO rtDescribeInformationlDTO) {
        return rtEngraveService.updateStatusRequirementtable(rtDescribeInformationlDTO);
    }

    @PostMapping("/searchByOids")
    @ApiOperation(value = "根据oid集合查询所有的打刻信息")
    public ResponseResult searchByOids(@RequestBody List<String> oids) {
        return rtEngraveService.searchByOids(oids);
    }

    @GetMapping("/searchEuemissionsnoByModel")
    @ApiOperation(value = "根据备案型号查询欧排号")
    public ResponseResult searchEuemissionsnoByModel(@RequestParam String model) {
        return rtEngraveService.searchEuemissionsnoByModel(model);
    }
}
